package com.mingye.components;

import com.mingye.board.BoardLoader;
import com.mingye.constants.LayoutConstants;
import com.mingye.listener.ResetClickListener;
import com.mingye.listener.SelectRoundItemListener;

import javax.swing.*;
import java.awt.*;
import java.util.List;

/**
 * 操作面板
 *
 * @author daixinyi
 */
public class OperationPanel extends JPanel {

    /**
     * 标签字体
     */
    private static final Font LABEL_FONT = new Font("Serif", Font.PLAIN, 32);

    /**
     * 按钮字体
     */
    private static final Font BUTTON_FONT = new Font("Serif", Font.PLAIN, 24);

    /**
     * 通关时，弹出通关字样
     */
    private JLabel winInfoLabel;

    /**
     * 重开按钮
     */
    private JButton resetBtn;

    /**
     * 关卡选择下拉列表
     */
    private JComboBox<String> roundComboBox;

    public OperationPanel(GameFrame gameFrame) {
        this.setLocation(LayoutConstants.BOARD_PANEL_WIDTH, 0);
        this.setSize(LayoutConstants.OPERATION_PANEL_WIDTH, LayoutConstants.OPERTAION_PANEL_HEIGHT);
        this.setLayout(null);

        roundComboBox = new JComboBox<>();
        List<String> boardKeys = BoardLoader.getBoardKeys();
        for (String boardKey : boardKeys) {
            roundComboBox.addItem(boardKey);
        }
        roundComboBox.setBounds(LayoutConstants.BOARD_PANEL_WIDTH + 50, 50, 200, 50);
        roundComboBox.setFont(LABEL_FONT);
        roundComboBox.setFocusable(false);
        roundComboBox.addItemListener(new SelectRoundItemListener(gameFrame));
        this.add(roundComboBox);

        resetBtn = new JButton("重新开始");
        resetBtn.setBounds(LayoutConstants.BOARD_PANEL_WIDTH + 50, 150, 200, 80);
        resetBtn.setFont(BUTTON_FONT);
        resetBtn.setFocusable(false);
        resetBtn.addActionListener(new ResetClickListener(gameFrame));
        this.add(resetBtn);

        winInfoLabel = new JLabel("");
        winInfoLabel.setBounds(LayoutConstants.BOARD_PANEL_WIDTH + 50, 300, 200, 50);
        winInfoLabel.setFont(LABEL_FONT);
        winInfoLabel.setFocusable(false);
        winInfoLabel.setForeground(Color.RED);
        this.add(winInfoLabel);

    }

    public JLabel getWinInfoLabel() {
        return winInfoLabel;
    }
}
